﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Web;
using System.Net;

namespace Sukul.SharePoint.Taxomatic.Service
{
    public class ServiceBase
    {
        protected void AddResponseHeader()
        {
            OutgoingWebResponseContext Response = WebOperationContext.Current.OutgoingResponse;
            HttpResponseHeader cacheHeader = HttpResponseHeader.CacheControl;
            String cacheControlValue = String.Format("max-age={0}, must-revalidate", 1);
            Response.Headers.Add(cacheHeader, cacheControlValue);
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
        }

        protected void HandleResponseError(DTO.WebServiceResponse response, Exception ex)
        {
            response.IsSuccess = false;
            response.ErrorMessage = ex.ToString();
            response.FriendlyErrorMessage = "An error occured in the business logic service.";
            response.ErrorStackTrace = ex.StackTrace;
        }
    }
}
